import axios from 'axios';

export default {
    install: function(Vue, options) {

        let service = {
            // 文本索引通行证
            Fulltext: (search, types) => {
                return axios.post('/admin/passport/search', {
                    'Text': search,
                    'Types': types
                });
            },

            // 删除通行证
            Remove: (userId) => {
                return axios.delete('/admin/passport/remove/' + userId);
            },

            // 查询符合条件的通行证数量
            QueryPassportsCount: (condition) => {
                return axios.post('/admin/passport/query/count', condition);
            },

            // 查询符合条件的通行证
            QueryPassports: (condition, pageIndex, pageSize) => {
                return axios.post(`/admin/passport/query?pageIndex=${pageIndex}&pageSize=${pageSize}`, condition);
            },

            // 查询符合条件的团队通行证数量
            QueryTeamsCount: (condition) => {
                return axios.post('/admin/team/query/count', condition);
            },

            // 查询符合条件的团队通行证
            QueryTeams: (condition, pageIndex, pageSize) => {
                return axios.post(`/admin/team/query?pageIndex=${pageIndex}&pageSize=${pageSize}`, condition);
            },

            // 导出通行证列表
            ExportPassports: (condition) => {
                return axios.post('/admin/passport/export', condition)
                    .then(ret => {
                        var link = aphf.file.ADDR + '/' + ret;

                        var a = document.createElement("a");
                        a.download = 'Passports.xls';
                        a.href = link;
                        a.click();
                    })
            },

            // 导出通行证打印稿
            ExportPrint: (condition) => {
                return axios.post('/admin/passport/export/print', condition)
                    .then(ret => {
                        var link = aphf.file.ADDR + '/' + ret;

                        var a = document.createElement("a");
                        a.download = 'Passports.doc';
                        a.href = link;
                        a.click();
                    })
            },
            
            // 导出团队通行证列表
            ExportTeams: (condition) => {
                return axios.post('/admin/team/export', condition)
                    .then(ret => {
                        var link = aphf.file.ADDR + '/' + ret;

                        var a = document.createElement("a");
                        a.download = 'Teams.xls';
                        a.href = link;
                        a.click();
                    })
            }              
        }

        Vue.prototype.$PassportService = service;
    }
}